# -*- coding: utf-8 -*-
# @Time    : 2017/10/18 14:44
# @Author  : David.Dong
# @Email   : dww102@gmail.com
# @Software: PyCharm Community Edition

# 运行calcShannonEnt
from decisionTreeAlgo import decisionTree
import numpy as np

# @return
# dataSet    :  数据集
# labels     :  类别标签集合，对应数据集列


def createDataSet():
    dataSet = [[1, 1, 'yes'],
               [1, 1, 'yes'],
               [1, 0, 'no'],
               [0, 1, 'no'],
               [0, 1, 'no']]
    labels = ['no Surfacing', 'flippers']
    return dataSet, labels

# 测试使用calcShannonEnt
myDat, labels = createDataSet()
print('----------')
print(myDat)
print('----------')
print(decisionTree.calcShannonEnt(myDat))
print('----------')
print(decisionTree.splitDataSet(myDat, 1, 1))
print('----------')
print(decisionTree.splitDataSet(myDat, 1, 0))

#测试3-3选择最好的数据集划分方式
print('------3-3------')

myDat2, labels2 = createDataSet()
bestFeature = decisionTree.chooseBestFeatureToSplit(myDat2)
print(myDat2)
print('最好增益：',bestFeature)


#测试3-4 创建树的代码
myDat3, labels3 = createDataSet()
myTree = decisionTree.createTree(myDat3, labels3)
print('------3-4------')
print(myTree)


















